home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 015a / memsz160.zip / SETTIMER.C < prev    next >
C/C++ Source or Header  |  1992-11-17  |  7KB  |  214 lines

  1. /***************************************************************** SETTIMER.C
  2.  *                                        *
  3.  *            Dialog: Set Timer Interval                *
  4.  *                                        *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_WIN
  8. #define INCL_WINSTDSPIN
  9. #include <os2.h>
  10.  
  11. #include "support.h"
  12. #include "settimer.h"
  13.  
  14.  
  15. /****************************************************************************
  16.  *                                        *
  17.  *               Definitions & Declarations                *
  18.  *                                        *
  19.  ****************************************************************************/
  20.  
  21.   // Function Prototypes
  22.  
  23. static METHODFUNCTION InitDlg ;
  24. static METHODFUNCTION Command ;
  25. static METHODFUNCTION OK ;
  26. static METHODFUNCTION Cancel ;
  27.  
  28.  
  29.   // Global Data
  30.  
  31. static SHORT id ;
  32. static PUSHORT TimerInterval ;
  33.  
  34.  
  35. /****************************************************************************
  36.  *                                        *
  37.  *    "SetTimer" Dialog Processor                        *
  38.  *                                        *
  39.  ****************************************************************************/
  40.  
  41. extern MRESULT EXPENTRY SetTimerProcessor
  42. (
  43.   HWND hwnd,
  44.   USHORT msg,
  45.   MPARAM mp1,
  46.   MPARAM mp2
  47. )
  48. {
  49.  /***************************************************************************
  50.   *                Declarations                    *
  51.   ***************************************************************************/
  52.  
  53.   static METHOD Methods [] =
  54.   {
  55.     { WM_INITDLG, InitDlg },
  56.     { WM_COMMAND, Command }
  57.   } ;
  58.  
  59.  /***************************************************************************
  60.   * Dispatch the message according to the method table and return the        *
  61.   *   result.  Any messages not defined above get handled by the system     *
  62.   *   default dialog processor.                         *
  63.   ***************************************************************************/
  64.  
  65.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  66. }
  67.  
  68. /****************************************************************************
  69.  *                                        *
  70.  *    Initialize Dialog                            *
  71.  *                                        *
  72.  ****************************************************************************/
  73.  
  74. static MRESULT APIENTRY InitDlg
  75.   HWND hwnd, 
  76.   USHORT msg,
  77.   MPARAM mp1, 
  78.   MPARAM mp2
  79. )
  80. {
  81.  /***************************************************************************
  82.   * Local Declarations                                *
  83.   ***************************************************************************/
  84.  
  85.   SETTIMER_PARMS *Parms = (SETTIMER_PARMS*) ( PVOIDFROMMP ( mp2 ) ) ;
  86.  
  87.  /***************************************************************************
  88.   * Save parameter data.                            *
  89.   ***************************************************************************/
  90.  
  91.   id = Parms->id ;
  92.   TimerInterval = Parms->TimerInterval ;
  93.  
  94.  /***************************************************************************
  95.   * Set the dialog help instance.                        *
  96.   ***************************************************************************/
  97.  
  98.   WinSetWindowUShort ( hwnd, QWS_ID, id ) ;
  99.  
  100.   if ( Parms->hwndHelp )
  101.   {
  102.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  103.   }
  104.  
  105.  /***************************************************************************
  106.   * Set the limits and initial value of the spin-button control.        *
  107.   ***************************************************************************/
  108.  
  109.   WinSendDlgItemMsg ( hwnd, id,
  110.     SPBM_SETLIMITS, (MPARAM)300L, (MPARAM)10L ) ;
  111.  
  112.   WinSendDlgItemMsg ( hwnd, id,
  113.     SPBM_SETCURRENTVALUE, (MPARAM)(*TimerInterval/100), NULL ) ;
  114.  
  115.  /***************************************************************************
  116.   * Return OK.                                    *
  117.   ***************************************************************************/
  118.  
  119.   return ( MRFROMSHORT ( FALSE ) ) ;
  120.  
  121.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  122. }
  123.  
  124. /****************************************************************************
  125.  *                                        *
  126.  *    Process command messages.                        *
  127.  *                                        *
  128.  ****************************************************************************/
  129.  
  130. static MRESULT APIENTRY Command
  131.   HWND hwnd, 
  132.   USHORT msg, 
  133.   MPARAM mp1, 
  134.   MPARAM mp2
  135. )
  136. {
  137.  /***************************************************************************
  138.   * Local Declarations                                *
  139.   ***************************************************************************/
  140.  
  141.   static METHOD Methods [] =
  142.   {
  143.     { DID_OK,      OK     },
  144.     { DID_CANCEL, Cancel },
  145.   } ;
  146.  
  147.  /***************************************************************************
  148.   * Dispatch the message without a default message processor.            *
  149.   ***************************************************************************/
  150.  
  151.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), NULL ) ) ;
  152.  
  153.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  154. }
  155.  
  156. /****************************************************************************
  157.  *                                        *
  158.  *    Process acceptance of new timer value.                    *
  159.  *                                        *
  160.  ****************************************************************************/
  161.  
  162. static MRESULT APIENTRY OK
  163.   HWND hwnd, 
  164.   USHORT msg, 
  165.   MPARAM mp1, 
  166.   MPARAM mp2
  167. )
  168. {
  169.  /***************************************************************************
  170.   * Save the results.                                *
  171.   ***************************************************************************/
  172.  
  173.   WinSendDlgItemMsg ( hwnd, id, SPBM_QUERYVALUE, TimerInterval, MPFROM2SHORT(NULL,SPBQ_UPDATEIFVALID) ) ;
  174.   *TimerInterval *= 100 ;
  175.  
  176.  /***************************************************************************
  177.   * Dismiss the dialog with a TRUE status.                    *
  178.   ***************************************************************************/
  179.  
  180.   WinDismissDlg ( hwnd, TRUE ) ;
  181.  
  182.   return ( 0 ) ;
  183.  
  184.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  185. }
  186.  
  187. /****************************************************************************
  188.  *                                        *
  189.  *    Process cancellation.                            *
  190.  *                                        *
  191.  ****************************************************************************/
  192.  
  193. static MRESULT APIENTRY Cancel
  194.   HWND hwnd, 
  195.   USHORT msg, 
  196.   MPARAM mp1, 
  197.   MPARAM mp2
  198. )
  199. {
  200.  /***************************************************************************
  201.   * Dismiss the dialog with a TRUE status.                    *
  202.   ***************************************************************************/
  203.  
  204.   WinDismissDlg ( hwnd, FALSE ) ;
  205.  
  206.   return ( 0 ) ;
  207.  
  208.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  209. }
  210.